package com.tingyukeji.fastpay.sport.ui.fragment;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.tingyukeji.fastpay.R;
import com.tingyukeji.fastpay.base.BaseFragment;
import com.tingyukeji.fastpay.databinding.SportRunFragmentBinding;
import com.tingyukeji.fastpay.sport.ui.activity.RecordMapActivity;
import com.tingyukeji.fastpay.sport.view.RiseNumberTextView;

/**
 * Created by Administrator on 2016/11/10.
 */

public class SportRunFragment extends BaseFragment implements View.OnClickListener{
    private SportRunFragmentBinding binding;
    private int type = 0;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (null == rootView) {
            binding = DataBindingUtil.inflate(inflater, R.layout.sport_run_fragment, container, false);
            rootView = binding.getRoot();
            initView();
        } else {
            ViewGroup parent = (ViewGroup) rootView.getParent();
            if (parent != null) {
                parent.removeView(rootView);
            }
        }
        initData();
        return rootView;
    }

    @Override
    protected void initView() {
        super.initView();
        Bundle bundle = getArguments();
        if (null != bundle){
            type = bundle.getInt("type", 0);
        }
        if (type == 0){
            binding.tvRunTitle.setText("健走总公里");
        }else if (type == 1){
            binding.tvRunTitle.setText("跑步总公里");
        }else if (type == 2){
            binding.tvRunTitle.setText("骑行总公里");
        }else {
            binding.tvRunTitle.setText("健走总公里");
        }
        binding.btGoSport.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(getActivity(), RecordMapActivity.class);
                startActivity(intent);
            }
        });
    }


    private void initData() {
    }

    /**
     * 给一个TextView设置一个数字增长动画
     */
    public void animText(RiseNumberTextView tv, int number) {
        // 设置数据
        tv.withNumber(number);
        // 设置动画播放时间
        tv.setDuration(3000);
        tv.start();
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
        }
    }
}
